home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 182_01 / bbsc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-30  |  28.6 KB  |  1,132 lines

  1. /*
  2.     bbsc.c
  3.  
  4.     BBS (Bulletin Board System) written in UNIX SYSTEM-III "C".
  5.  
  6.         Support files needed:
  7.             bbscdef.h
  8.             bbscport.o or bbscport.c
  9.             bbsclock.o or bbsclock.c
  10.             bbscfile.o or bbscfile.c
  11.             bbscmisc.o or bbscmisc.c
  12.  
  13.                 Mike Kelly
  14.  
  15.     03/09/83 v1.0   written
  16.     07/07/83 v1.0   updated
  17. */
  18. #define MAINMOD 1
  19. #include "bbscdef.h"
  20.  
  21. #define LASTDATE  " 02/07/84 "
  22.  
  23. #define PGMNAME "BBSc    "
  24. #define VERSION " 1.1 "
  25.  
  26.  
  27. main()
  28.     {
  29.     int i;
  30. /*
  31. *       init global variables
  32. */
  33.     debug   = FALSE;
  34.     statcnt = 0;
  35.     xpert   = FALSE;
  36.     active  = TRUE;
  37.  
  38.     w_fname[0] = '\0';
  39.     w_lname[0] = '\0';
  40.     strcpy(w_password,"MPK0");
  41.  
  42.     u_fname[0] = '\0';
  43.     u_lname[0] = '\0';
  44.     strcpy(u_password,"MPK0");
  45.     u_time1[0] = '\0';
  46.     u_date1[0] = '\0';
  47.     u_time2[0] = '\0';
  48.     u_date2[0] = '\0';
  49.     u_city[0]  = '\0';
  50.  
  51.     mm[0]    = '\0';
  52.     dd[0]    = '\0';
  53.     yy[0]    = '\0';
  54.     month[0] = '\0';
  55.     day[0]   = '\0';
  56.     year[0]  = '\0';
  57.     date[0]  = '\0';
  58.     week[0]  = '\0';
  59.     ttime[0] = '\0';
  60.  
  61.     strcpy(msg_delete,"0");
  62.     msg_no[0]   = '\0';
  63.     msg_date[0] = '\0';
  64.     msg_date[0] = '\0';
  65.     msg_time[0] = '\0';
  66.     msg_to[0]   = '\0';
  67.     msg_from[0] = '\0';
  68.     msg_pass[0] = '\0';
  69.     msg_subject[0] = '\0';
  70.     msg_text[0] = '\0';
  71.  
  72.     stop_that = FALSE;
  73.  
  74. /*   get date and time from the clock   */
  75.  
  76.     gettime(ttime);
  77.     getdate(mm,dd,yy,month,day,year,date,week);
  78.  
  79.     portinit() ;    /* init terminal modes */
  80.     signon()   ;
  81.     driver()   ;
  82.     portrst()  ;    /* undo any special modes */        
  83.     }
  84. /*  end of mainline routine     */
  85.  
  86. driver()
  87.     {
  88. char    linebuf[MAXLINE],
  89.     buf[128],
  90.     *bufptr,        /* ptr to buf */
  91.     usercd[100],        /* user record */
  92.     *userptr,       /* ptr to usercd */
  93.     cmd[2];
  94.  
  95. int cnt,
  96.     ok_sw,
  97.     case_sw,
  98.     i,
  99.     num0,
  100.     num1,
  101.     num2;
  102.  
  103.     cnt = 0;
  104.     ok_sw   = TRUE;
  105.     bufptr  = buf;
  106.     xpert   = FALSE;
  107.     cmd[0]  = '\0';
  108.  
  109.     while (active)
  110.         {
  111.         stop_that = FALSE ;     /* reset switch */
  112.         portsout(CRLF);
  113.         if (!xpert)
  114.             {
  115.             portsout("Commands: B,C,E,G,K,N,Q,R,S,W,X or ? ");
  116.             }
  117.         portsout("===> ");
  118.         portsin(cmd,1);
  119.         portsout(CRLF);
  120.  
  121.         *cmd = toupper(*cmd) ;
  122.  
  123.         switch (cmd[0])
  124.             {
  125.             case ('C'):     /* Unix */
  126.                 cmd_c();
  127.                 break;
  128.             case ('E'):     /* enter msg */
  129.                 cmd_e();
  130.                 break;
  131.             case ('G'):     /* goodby */
  132.                 cmd_g();
  133.                 break;
  134.             case ('K'):     /* kill msg */
  135.                 cmd_k();
  136.                 break;
  137.             case ('Q'):     /* quick scan */
  138.                 cmd_q();
  139.                 break;
  140.             case ('R'):     /* read msg */
  141.                 cmd_r();
  142.                 break;
  143.             case ('S'):     /* scan msg */
  144.                 cmd_s();
  145.                 break;
  146.             case ('X'):     /* expert toggle */
  147.                 cmd_x();
  148.                 break;
  149.             case ('N'):     /* print new-user stuff */
  150.                 cmd_p(NEWUSER);
  151.                 break;
  152.             case ('W'):     /* print welcome file */
  153.                 cmd_p(WELCOME);
  154.                 break;
  155.             case ('B'):     /* print bulletins */
  156.                 cmd_p(BULLETINS);
  157.                 break;
  158.             case ('?'):     /* help */
  159.                 cmd_p(HELP);
  160.                 break;
  161.             default:
  162.                 break;
  163.             }
  164.  
  165.         }
  166.     }
  167. /*  end of function     */
  168.  
  169. cmd_g()         /* good-by */
  170.     {
  171.     active = FALSE;
  172.     portsout("\r\nThanks for calling ");
  173.     portsout(w_fname) ;
  174.     portsout(CRLF)    ;
  175.     sleep(5)          ;     /* for the Smartmodem */
  176.     portsout("+")     ;     /* get the modems attention */
  177.     portsout("+")     ;     /* get the modems attention */
  178.     portsout("+")     ;     /* get the modems attention */
  179.     sleep(15)         ;         /* for the Smartmodem */
  180.     gobble()          ;
  181.     portsout("ATH")   ;     /* hang up the phone */
  182.     portsout(CRLF)    ;
  183.     sleep(15)         ;         /* for the Smartmodem */
  184.     }
  185. /*  end of function     */
  186.  
  187. cmd_c()         /* go to the operating system level */
  188.     {
  189.     if ((inbuf=fopen(SYSTEM,"r")) == NULL)
  190.         {
  191.         portsout(CRLF) ;
  192.         portsout("Exiting to the operating system level!") ;
  193.         portsout(CRLF) ;
  194.         }
  195.     else
  196.         {
  197.         porttype(inbuf);    /* type a file to port */
  198.         close(inbuf);
  199.         }
  200.     active = FALSE;
  201.     }
  202. /*  end of function     */
  203.  
  204. cmd_e()         /* enter a message */
  205.     {
  206.     int entering,
  207.         editing,
  208.         cnt1;
  209.     char    msg[50],
  210.         l_cnt[3],
  211.         ans[2];
  212.  
  213.     entering = editing = TRUE;
  214.     cnt1 = 0;
  215.     l_cnt[0] = '0';         /* init line count */
  216.     msg_text[0] = '\0';     /* init message text area */
  217.  
  218.     portsout(CRLF);
  219.     portsout("This will be message # ");
  220.     portsout(h_next_msg);
  221.     portsout(CRLF);
  222.     portsout("                             ____.____1____.____2\r\n");
  223.     portsout("Who is the message for  ===> ");
  224.     portsin(msg_to,20);
  225.     portsout(CRLF);
  226.     portsout("What is the subject     ===> ");
  227.     portsin(msg_subject,20);
  228.     portsout(CRLF);
  229.  
  230.     portsout(CRLF) ;
  231.     portsout("A line can contain 40 characters, up to 20 lines.") ;
  232.     portsout(CRLF) ;
  233.     portsout("To end, enter a carriage return on an empty line.") ;
  234.     portsout(CRLF) ;
  235.     portsout(CRLF) ;
  236.     portsout("    .___.____1____.____2____.____3____.____4") ;
  237.     portsout(CRLF) ;
  238.  
  239.     while (entering)        /* get the text of the message */
  240.         {
  241.         linecnt(l_cnt);     /* calc line count */
  242.  
  243.         portsout(l_cnt);    /* show line count */
  244.         portsout("> ");     /*  and prompt */
  245.  
  246.         portsin(msg,40);
  247.         portsout(CRLF);
  248.  
  249.         strcat(msg,"\n");   /* put a <lf> on each line */
  250.  
  251.         if (strlen(msg) < 2)        /* count cr too */
  252.             {
  253.             entering = FALSE;   /* all done */
  254.             }
  255.         else
  256.             {
  257.             strcat(msg_text,msg);   /* append each line to text */
  258.             }
  259.         if ((++cnt1) > 19)      /* only allow 20 lines */
  260.             {
  261.             entering = FALSE;   /* all done */
  262.             }
  263.         }
  264.  
  265.     while (editing)     /* save it, fix it, list it, or get out */
  266.         {
  267.         portsout(CRLF);
  268.         portsout("(S)ave,   (L)ist,   or (Q)uit") ;
  269.         portsout(CRLF);
  270.         portsout("(D)elete, (I)nsert, or (E)dit line ==> ") ;
  271.         portsin(ans,1);         /* get a byte */ 
  272.         portsout(CRLF);
  273.  
  274.         *ans = toupper(*ans) ;
  275.  
  276.         switch (ans[0])         /* get 1 byte */
  277.             {
  278.             case ('S'):     /* save message */
  279.                 savemsg();
  280.                 editing = FALSE; /* get out of while */
  281.                 break;
  282.             case ('E'):     /* edit message */
  283.             case ('I'):     /* edit message */
  284.             case ('D'):     /* edit message */
  285.                 editmsg(*ans);
  286.                 break;
  287.             case ('L'):     /* list message */
  288.                 listmsg();
  289.                 break;
  290.             case ('Q'):     /* get out w/out saving */
  291.                 editing = FALSE; /* get out of while */
  292.                 break;
  293.             default:
  294.                 portsout(CRLF);
  295.                 portsout("Shall we try that one again?\r\n");
  296.                 break;
  297.             }   
  298.         }
  299.  
  300.     }
  301. /*  end of function     */
  302.  
  303. linecnt(lcnt)           /* 2 byte string of line numbers */
  304. char    *lcnt;
  305.     {
  306.     int icnt;
  307.     char    xcnt[4];
  308.  
  309.     icnt = atoi(lcnt);
  310.     if (++icnt < 10)
  311.         {
  312.         strcpy(lcnt,"0");
  313.         itoa(xcnt,icnt);
  314.         strcat(lcnt,xcnt);
  315.         }
  316.     else
  317.         {
  318.         itoa(xcnt,icnt);
  319.         strcpy(lcnt,xcnt);
  320.         }
  321.     return;
  322.     }
  323. /*  end of function     */
  324.  
  325. savemsg()               /* save a message */
  326.     {
  327.     int fd;
  328.  
  329.     portsout("Saving...\r\n");
  330.  
  331.     strcpy(msg_delete,"0");     /* delete byte */
  332.     strcpy(msg_date, mm);
  333.     strcat(msg_date,"/");
  334.     strcat(msg_date, dd);
  335.     strcat(msg_date,"/");
  336.     strcat(msg_date, yy);
  337.  
  338.     strcpy(msg_time,ttime);     /* and the time */
  339.  
  340.     strcpy(msg_from,w_fname);   /* and the from name */
  341.     strcat(msg_from," ");
  342.     strcat(msg_from,w_lname);
  343.  
  344.     portsout("Updating the message file...\r\n");
  345.     if ((fd = msgopen(2)) == ERROR)     /* open i/o */
  346.         {
  347.         return(ERROR);
  348.         }
  349.     msgwrt(fd);     /* write the message */
  350.     msgclose(fd);
  351.  
  352.     strcpy(h_date,msg_date);
  353.     portsout("Updating the header  file...\r\n");
  354.     hdrwrt();       /* update the header file */
  355.     }
  356. /*  end of function     */
  357.  
  358.  
  359. listmsg()
  360.     {
  361.     char    *ptr,
  362.         byte,
  363.         lcnt[3];
  364.     int i;
  365.  
  366.     ptr = msg_text;     /* ptr points to start of text */
  367.     lcnt[0] = '0';      /* start linecount at zero     */
  368.     
  369.     portsout(CRLF) ;
  370.     while (*ptr != 0)
  371.         {
  372.         linecnt(lcnt);
  373.         portsout(lcnt);         /* put out line number */
  374.         portsout(">");
  375.         while (byte = *ptr++)
  376.             {
  377.             if (byte == '\n')   /* we dont save <cr>, so add */
  378.                 {       /*  it here when find a <cr> */
  379.                 portsout(CRLF) ;
  380.                 break ;
  381.                 }
  382.             else portout(byte) ;
  383.             }
  384.         }
  385.     }
  386. /*  end of function     */
  387.  
  388. editmsg(tflag) char tflag ;
  389.     {
  390.     char    ans[3] ;
  391.     int lnum ;      /* line number to edit */
  392.  
  393.     while(1)
  394.         {
  395.         portsout(CRLF);
  396.         portsout("Enter line number to ") ;
  397.         if(tflag == 'E') portsout("edit,") ;
  398.         else if(tflag == 'D') portsout("delete,") ;
  399.         else if(tflag == 'I') portsout("insert after,") ;
  400.         else return ;
  401.         portsout(CRLF);
  402.         portsout("   or RETURN to exit ==> ");
  403.         portsin(ans,2);     /* only 20 lines possible */
  404.         portsout(CRLF);
  405.         lnum = atoi(ans);
  406.         if (lnum <= 0)
  407.             {
  408.             break;      /* out of while and return */
  409.             }
  410.         if ((lnum < 20) || ((lnum == 20) && (tflag != 'I')))
  411.             {
  412.             editline(lnum,tflag) ; break ;
  413.             }
  414.         else            /* else slap on hand and loop around */
  415.             {
  416.             portsout("Aw come on, there can only be 20 lines!");
  417.             portsout(CRLF);
  418.             portsout("Shall we try that again?");
  419.             portsout(CRLF);
  420.             }
  421.         }       
  422.     }
  423. /*  end of function     */
  424.  
  425. editline(line_no,tflag)
  426. int line_no ; char tflag ;
  427.     {
  428.     char    work_msg[(20*40)+40],   /* work message area */
  429.         *work_ptr,      /* pointers */
  430.         *msg_ptr,
  431.         *new_ptr,
  432.         new_line[40+1],     /* new line to replace in text */
  433.         byte ;
  434.     int i ;         /* a counter */
  435.  
  436.     work_msg[0] = '\0';     /* init strings */
  437.     new_line[0] = '\0';
  438.     i = 1 ;             /* assume at line one */
  439.  
  440.     work_ptr = work_msg;    /* put the addr of work_msg in the pointer */
  441.     msg_ptr  = msg_text;    /* put the addr of the global message in ptr */
  442.     new_ptr  = new_line;    /* the new line too */
  443.  
  444.     while(byte = *msg_ptr)  /* if at the line then found it's start */
  445.         {
  446.         if(line_no == i) break ;    /* found the line        */
  447.         while(byte = *msg_ptr++)    /* move msg to work area */
  448.             {           /*  until end of msg */
  449.             *work_ptr++ = byte;
  450.             if (byte == '\n')   /* end of line? */
  451.                 {
  452.                 i++ ; break ;   /* then stop moving */
  453.                 }
  454.             }
  455.         }
  456.     if (byte == 0)  /* if true then there ain't no such beast */
  457.         {
  458.         portsout("Hmmm, can't seem to find that line");
  459.         portsout(CRLF);
  460.         portsout("   give me another chance, ok?");
  461.         portsout(CRLF);
  462.         return;     /* here we go round the mulberry bush */
  463.         }
  464.  
  465.     portsout(CRLF);
  466.     portsout("Line to ") ;
  467.     if(tflag == 'E')
  468.         { portsout("edit") ; }
  469.     else if(tflag == 'I')
  470.         { portsout("insert after"); }
  471.     else if(tflag == 'D')
  472.         {
  473.         portsout("delete");
  474.         }
  475.     else return ;
  476.  
  477.     portsout(" is:") ;
  478.     portsout(CRLF) ;
  479.     portsout(">") ;
  480.  
  481.     while(byte = *msg_ptr++)        /* show the line to edit */
  482.         {
  483.         if(tflag == 'I')
  484.             {
  485.             *work_ptr++ = byte ;    /* if adding new line copy */
  486.             }
  487.         if(byte == '\n') break ;
  488.         portout(byte);
  489.         }
  490.     portsout(CRLF) ;
  491.  
  492.     if(tflag == 'D')
  493.         {
  494.         portsout("Are you sure? (Y/N) ==> ");
  495.         byte = portin() ;   /* get answer */
  496.         portout(byte) ;     /* send it back */
  497.         if ((byte != 'Y') && (byte != 'y')) return ;
  498.         }
  499.     else
  500.         {
  501.         portsout("Enter new line:") ;
  502.         portsout(CRLF) ;
  503.         portsout(">") ;
  504.         portsin(new_line,40) ;
  505.         portsout(CRLF) ;
  506.         strcat(new_line,"\n\0") ;       /* lf at end new line */
  507.         while (*work_ptr++ = *new_ptr++)    /* tag on new line to */
  508.             { ; }               /*  work area */
  509.         *work_ptr--;                /* back up one */
  510.         }
  511.  
  512.     while (*work_ptr++ = *msg_ptr++)    /* now move in rest of */
  513.         { ; }               /*  message to work area */
  514.     *work_ptr++ = '\0';     /* for luck */
  515.  
  516.     strcpy(msg_text,work_msg);  /* replace the message with the */
  517.                     /*  new line inserted */
  518.     }
  519. /*  end of function     */
  520.  
  521. cmd_k()
  522.     {
  523.     char    ans[11];
  524.     int kill_msg,
  525.         fd,
  526.         rc;
  527.  
  528.     portsout(CRLF) ;
  529.     portsout("Enter message number to delete ==> ") ;
  530.     portsin(ans,10) ;
  531.     portsout(CRLF) ;
  532.     kill_msg = atoi(ans) ;
  533.     fd = msgopen(2) ;       /* open i/o */
  534.     if ((rc = msgread(fd,kill_msg)) == ERROR || rc == 0)
  535.         {
  536.         portsout("Can't delete that message!") ;
  537.         portsout(CRLF) ;
  538.         return ;
  539.         }
  540.     portsout("Deleting message...") ;
  541.     portsout(CRLF) ;
  542.     strcpy(msg_delete,"9") ;        /* mark for deletion */
  543.     if (msgrewrt(fd,kill_msg) == ERROR) /* re-write the record just read */
  544.         {
  545.         portsout("Sorry, can't delete that message");
  546.         portsout(CRLF);
  547.         return;
  548.         }
  549.     msgclose(fd);
  550.     portsout("Message ");
  551.     portsout(ans);
  552.     portsout(" has been deleted!") ;
  553.     portsout(CRLF);
  554.     return;
  555.     }
  556. /*  end of function     */
  557.  
  558. cmd_q()
  559.     {
  560.     char    ans[11];
  561.     int q_msg,
  562.         fd,
  563.         rc;
  564.  
  565.     if ((fd = msgopen(0)) == ERROR)     /* open input */
  566.         {
  567.         return(ERROR);
  568.         }
  569.     portsout(CRLF);
  570.     portsout("Enter starting message number -- RETURN to exit  ==> ");
  571.     portsin(ans,10);
  572.     q_msg = atoi(ans);
  573.     if (q_msg == 0)         /* = 0 all done */
  574.         {
  575.         msgclose(fd);
  576.         return;
  577.         }
  578.     portsout(CRLF);
  579.     portsout(CRLF);
  580.     portsout("No.      Date            Subject") ;
  581.     portsout(CRLF);
  582.     portsout("---------------------------------------");
  583.     portsout(CRLF);
  584.  
  585.     while ((rc = msgread(fd,q_msg++)) != ERROR)
  586.         {           /* read until eof or error */
  587.         if (rc == 0)
  588.             {
  589.             continue;   /* not a valid msg */
  590.             }
  591.         portlsout(msg_no  , 6) ;
  592.         portlsout(msg_date,12) ;
  593.         portsout(msg_subject ) ;
  594.         portsout(CRLF);
  595.         if (stop_that)      /* ctl-K ? */
  596.             {
  597.             stop_that = FALSE;
  598.             break;
  599.             }
  600.         }
  601.     msgclose(fd);
  602.     }
  603. /*  end of function     */
  604.  
  605. cmd_r()
  606.     {
  607.     char    msgno[10],
  608.         *text,
  609.         byte0;
  610.     int msg,
  611.         fd,
  612.         rc;
  613.  
  614.     if ((fd = msgopen(0)) == ERROR)     /* open input */
  615.         {
  616.         return(ERROR);
  617.         }
  618.     portsout("\r\n\n");
  619.     portsout("Enter the message number to read");
  620.     portsout(" - RETURN to exit   ==> ");
  621.  
  622.     while (!stop_that)
  623.         {
  624.         portsin(msgno,9);
  625.         portsout(CRLF);
  626.         msg = atoi(msgno);  /* make the no. integer */
  627.         if (msg == 0)
  628.             {
  629.             break;
  630.             }
  631.         if ((rc = msgread(fd,msg)) == 0 || rc == ERROR)
  632.             {
  633.             portsout("Message ");
  634.             portsout(msgno);
  635.             portsout(" not found\r\n");
  636.             }
  637.         else
  638.             {
  639.             portsout(CRLF);
  640.             portsout("No. ");
  641.             portsout(msg_no);
  642.             portsout("  ");
  643.             portsout(msg_date);
  644.             portsout("  ");
  645.             portsout(msg_time);
  646.             portsout(CRLF);
  647.  
  648.             portsout("From: ");
  649.             portsout(msg_from);
  650.             portsout("   To: ");
  651.             portsout(msg_to);
  652.             portsout(CRLF);
  653.  
  654.             portsout("Subject: ");
  655.             portsout(msg_subject);
  656.             portsout(CRLF);
  657.             portsout(CRLF);
  658.  
  659.             text = msg_text;
  660.             while (byte0 = (*text++))
  661.                 {
  662.                 if (byte0 == '\n')
  663.                     {
  664.                     portout('\r');
  665.                     }
  666.                 portout(byte0);
  667.                 if (stop_that)
  668.                     {
  669.                     stop_that = FALSE;
  670.                     msgclose(fd);
  671.                     return;
  672.                     }
  673.                 }
  674.             }
  675.         portsout(CRLF);
  676.         portsout("Number or RETURN to exit ==> ") ;
  677.         }
  678.     msgclose(fd);
  679.     }
  680. /*  end of function     */
  681.  
  682. cmd_s()
  683.     {
  684.     char    ans[11];
  685.     int q_msg,
  686.         fd,
  687.         rc;
  688.  
  689.     if ((fd = msgopen(0)) == ERROR)     /* open input */
  690.         {
  691.         return(ERROR);
  692.         }
  693.     portsout(CRLF);
  694.     portsout("Enter starting message number -- RETURN to exit ) ==> ") ;
  695.     portsin(ans,10);
  696.     q_msg = atoi(ans);
  697.     if (q_msg == 0)
  698.         {
  699.         return;
  700.         }
  701.     portsout(CRLF);
  702.     portsout(CRLF);
  703.     portsout("No.     Date          From         ") ;
  704.     portsout("      To                    Subject") ;
  705.     portsout(CRLF);
  706.     portsout("---------------------------------------") ;
  707.     portsout("---------------------------------------") ;
  708.     portsout(CRLF);
  709.  
  710.     while ((rc = msgread(fd,q_msg++)) != ERROR)
  711.         {           /* read until eof or error */
  712.         if (rc == 0)
  713.             {
  714.             continue;   /* not a valid msg */
  715.             }
  716.         portlsout(msg_no  , 6) ;
  717.         portlsout(msg_date,12) ;
  718.         portlsout(msg_from,21) ;
  719.         portlsout(msg_to  ,21) ;
  720.         portsout(msg_subject)  ;
  721.         portsout(CRLF);
  722.         if (stop_that)
  723.             {
  724.             stop_that = FALSE;
  725.             break;
  726.             }
  727.         }
  728.     msgclose(fd);
  729.     }
  730. /*  end of function     */
  731.  
  732. cmd_x()
  733.     {
  734.     xpert = !xpert;     /* flip the expert mode */
  735.     }
  736. /*  end of function     */
  737.  
  738. cmd_p(name) char *name ;    /* type a file */
  739.     {
  740.     if ((inbuf=fopen(name,"r")) == NULL)
  741.         {
  742.         portsout("\r\nSorry, needed file not available\r\n");
  743.         }
  744.     else
  745.         {
  746.         porttype(inbuf);    /* type a file to port */
  747.         close(inbuf);       /* close it to free up fcb */
  748.         }
  749.     }
  750. /*  end of function     */
  751.  
  752. signon()    
  753.     {
  754.     char    byte0 ;
  755.  
  756.     int i ;
  757.     int tfd ;
  758.  
  759.     portsout(PGMNAME)   ;
  760.     portsout("Version") ;
  761.     portsout(VERSION)   ;
  762.     portsout(LASTDATE)  ;
  763.     portsout(CRLF)      ;
  764. /*
  765. *           type welcome file
  766. */
  767.     if ((inbuf=fopen(WELCOME,"r")) == NULL)
  768.         {
  769.         portsout(CRLF) ;
  770.         portsout("Welcome file not present, welcome anyhow!") ;
  771.         portsout(CRLF) ;
  772.         }
  773.     else
  774.         {
  775.         porttype(inbuf);    /* type a file to port */
  776.         close(inbuf);
  777.         }
  778.     portsout("On at "); /* give date and time of signon */
  779.     portsout(ttime);
  780.     portsout("  ");
  781.     portsout(week);
  782.     portsout("  ");
  783.     portsout(date);
  784. /*
  785. *           get name
  786. */
  787.     while (1)
  788.         {
  789.         portsout("\r\n\n");
  790.         portsout("Enter your first name   ==> ");
  791.         portsin(w_fname,20);
  792.         fix_name(w_fname) ;
  793.         portsout(CRLF);
  794.         portsout("Enter your last name    ==> ");
  795.         portsin(w_lname,20);
  796.         fix_name(w_lname) ;
  797.         portsout("\r\r\n");
  798.         portsout("Hello ");
  799.         portsout(w_fname);
  800.         portsout(" ");
  801.         portsout(w_lname);
  802.         portsout(CRLF);
  803.         portsout("Did I get your name right?  (Y/N) ==> ");
  804.         byte0 = portin();   /* get answer */
  805.         portout(byte0);     /* send it back */
  806.         if ((byte0 == 'Y') || (byte0 == 'y'))
  807.             {
  808.             portsout(CRLF) ;
  809.             wcaller() ;
  810.             if (checkuser())
  811.                 {
  812.                 break ; /* got a valid user */
  813.                 }
  814.             else
  815.                 {
  816.                 return ; /* do not have a valid user */
  817.                 }
  818.             }
  819.         }
  820. /*
  821. *           type bulletins file
  822. */
  823.     if ((inbuf=fopen(BULLETINS,"r")) == NULL)
  824.         {
  825.         portsout("\r\nNo Bulletins today\r\n");
  826.         }
  827.     else
  828.         {
  829.         porttype(inbuf);    /* type a file to port */
  830.         close(inbuf);
  831.         }
  832.  
  833.     hdrread();      /* read msgs header file into memory */
  834. /*
  835. *           end of signon
  836. */
  837.  
  838.     }
  839. /*  end of function     */
  840.         
  841. fix_name(adr) char *adr ;
  842.     {
  843.     char *adrs ;
  844.     adrs = adr ;
  845.     while(*adrs)
  846.         {
  847.         *adrs = tolower(*adrs) ;
  848.         adrs++ ;
  849.         }
  850.     *adr = toupper(*adr) ;
  851.     }
  852.  
  853. wcaller()   /* added this caller to the caller file */
  854.     {
  855.     int code ;
  856.     char    l_date[80] ;
  857.  
  858.     strcpy(l_date,  mm) ;
  859.     strcat(l_date, "/") ;
  860.     strcat(l_date,  dd) ;
  861.     strcat(l_date, "/") ;
  862.     strcat(l_date,  yy) ;
  863.  
  864.     if ((inbuf=fopen(CALLERS,"a")) == NULL) /* create or open for append */
  865.         {
  866.         portsout(CRLF) ;
  867.         portsout("Can't open/create callers file!");
  868.         portsout(CRLF) ;
  869.         return ;
  870.         }
  871.     code = fprintf(inbuf,"%s %s %s %s",l_date,ttime,w_fname,w_lname) ;
  872.     if (code < 0)
  873.         {
  874.         portsout(CRLF) ;
  875.         portsout("Caller file has problem writing") ;
  876.         portsout(CRLF) ;
  877.         }
  878.     else
  879.         {
  880.         fputs("\n",inbuf) ; /* put lf on end of each record */
  881.         }
  882.     fclose(inbuf) ;
  883.     /* now also save caller as last-caller */
  884.     if ((inbuf=fopen(LASTCALL,"w")) == NULL) /* create or open for write */
  885.         {
  886.         portsout(CRLF) ;
  887.         portsout("Can't open/create last-caller file!");
  888.         portsout(CRLF) ;
  889.         return ;
  890.         }
  891.     code = fprintf(inbuf,"%s %s %s %s",l_date,ttime,w_fname,w_lname) ;
  892.     if (code < 0)
  893.         {
  894.         portsout(CRLF) ;
  895.         portsout("Last-caller file has problem writing") ;
  896.         portsout(CRLF) ;
  897.         }
  898.     else
  899.         {
  900.         fputs("\n",inbuf) ; /* put lf on end of record */
  901.         }
  902.     fclose(inbuf) ;
  903.     }
  904. /*  end of function     */
  905.  
  906. checkuser()         /* returns 1 when find a match */
  907.     {
  908.     char    name[50] ;
  909.  
  910.     if ((inbuf=fopen(USERS,"r")) == NULL)
  911.         {
  912.         portsout(CRLF) ;
  913.         portsout("User file not present, will log you on as");
  914.         portsout(" a GUEST!");
  915.         portsout(CRLF) ;
  916.         strcpy(u_fname,"GUEST");
  917.         strcpy(u_lname," ");
  918.         strcpy(u_password,"MPK0");
  919.         return(TRUE);
  920.         }
  921.  
  922.     portsout(CRLF) ;
  923.     portsout("Checking user file...");
  924.     portsout(CRLF) ;
  925.  
  926.     while (readuser(inbuf) != 0)    /* look until eof on users file */
  927.         {
  928.         if ((strcmp(u_fname,w_fname) == 0) &&
  929.             (strcmp(u_lname,w_lname) == 0))
  930.             {
  931.             if (checkpass() == OK)
  932.                 {
  933.                 fclose(inbuf) ;
  934.                 return(TRUE)  ; /* passwords match */
  935.                 }
  936.             else
  937.                 {
  938.                 fclose(inbuf) ;
  939.                 return(FALSE) ; /* passwords dont match */
  940.                 }
  941.             }
  942.         }
  943.     fclose(inbuf) ;
  944.     newuser() ;     /* not on file, so add 'em */
  945. /*
  946. *           type new-user file
  947. */
  948.     if ((inbuf=fopen(NEWUSER,"r")) != NULL)
  949.         {
  950.         porttype(inbuf) ;   /* type a file to port */
  951.         close(inbuf) ;
  952.         }
  953.     return(TRUE) ;
  954.     }
  955. /*  end of function     */
  956.  
  957. checkpass()         /* returns TRUE (1) when equal passwords */
  958.     {
  959.     char    *passptr;
  960.     int j,
  961.         i;
  962.  
  963.     passptr = w_password;   /* give passptr the addr of w_password */
  964.  
  965.     for (i = 0; i < 3; i++)     /* give 'em 3 tries to get it right */
  966.         {
  967.         portsout(CRLF) ;
  968.         portsout("Enter your password  ==> ") ;
  969.         for (j=0; j < 4; j++)   /* password is 4 long */
  970.             {
  971. /*          *passptr++ = portin() ;
  972. */
  973.             w_password[j] = portin() ;
  974.             portout('_');
  975.             }
  976. /*      *passptr++ = '\0';
  977. */
  978.         w_password[j] = '\0';
  979.  
  980.         if ((strcmp(w_password,u_password)) == 0)
  981.             {
  982.             return(OK); /* passwords match */
  983.             }
  984.         portsout(" Incorrect!\007") ;
  985.         }
  986.     if (i >= 3)
  987.         {
  988.         portsout(CRLF) ;
  989.         portsout("Sorry, but three tries is all you get!") ;
  990.         portsout(CRLF) ;
  991.         portsout("  Goodby....") ;
  992.         cmd_g()        ;            /* hang up the phone   */
  993.         portsout(CRLF) ;
  994.         return(ERROR);          /* bad try on password */
  995.         }
  996.     }
  997. /*  end of function     */
  998.  
  999. newuser()
  1000.     {
  1001.     char    pword[5];
  1002.     int j;
  1003.  
  1004.     if ((inbuf=fopen(USERS,"a")) == NULL)
  1005.         {
  1006.         portsout(CRLF) ;
  1007.         portsout("Can't open/create the user file for writing!") ;
  1008.         portsout(CRLF) ;
  1009.         return ;
  1010.         }
  1011.  
  1012.     strcpy(u_fname,w_fname);
  1013.     strcpy(u_lname,w_lname);
  1014.  
  1015.     strcpy(u_time1,ttime);
  1016.     strcpy(u_time2,ttime);
  1017.  
  1018.     strcpy(u_date1,mm);
  1019.     strcat(u_date1,"/");
  1020.     strcat(u_date1,dd);
  1021.     strcat(u_date1,"/");
  1022.     strcat(u_date1,yy);
  1023.  
  1024.     strcpy(u_date2,mm);
  1025.     strcat(u_date2,"/");
  1026.     strcat(u_date2,dd);
  1027.     strcat(u_date2,"/");
  1028.     strcat(u_date2,yy);
  1029.  
  1030.     portsout(CRLF) ;
  1031.     portsout("Welcome, as a new user I need a few pieces") ;
  1032.     portsout(" of information.") ;
  1033.     portsout(CRLF) ;
  1034.     portsout(CRLF) ;
  1035.  
  1036.     portsout("Please enter the City, State you are from ===> ");
  1037.     portsin(u_city,30);
  1038.     portsout(CRLF);
  1039.  
  1040.     while (1)
  1041.         {
  1042.         portsout(CRLF) ;
  1043.         portsout("Ok, now I need a 4 character password ===> ");
  1044.         for (j=0; j < 4; j++)   /* password is 4 long */
  1045.             {
  1046.             u_password[j] = portin();
  1047.             portout('_');
  1048.             }
  1049.         u_password[j] = '\0';
  1050.         portsout(CRLF) ;
  1051.  
  1052.         portsout("Just to make sure, enter it again ===> ");
  1053.         for (j=0; j < 4; j++)   /* password is 4 long */
  1054.             {
  1055.             w_password[j] = portin();
  1056.             portout('_');
  1057.             }
  1058.         w_password[j] = '\0';
  1059.         portsout(CRLF) ;
  1060.  
  1061.         if (strcmp(u_password,w_password) == 0)
  1062.             {
  1063.             break ; /* get it right twice, then get out */
  1064.             }
  1065.         portsout(CRLF) ;
  1066.         portsout("hmmmm, one of us forgot it already") ;
  1067.         portsout(CRLF) ;
  1068.         portsout("  let's try it again!!") ;
  1069.         portsout(CRLF) ;
  1070.         portsout(CRLF) ;
  1071.         }
  1072.  
  1073.     wrtuser(inbuf) ;    /* write a user record */
  1074.     fflush(inbuf)  ;    /* ok leor, just for you */
  1075.     fclose(inbuf)  ;    /* close the file after new user added */
  1076.     }
  1077. /*  end of function     */
  1078.  
  1079. readuser(buf)   /* read a record from the user file */
  1080.         /*  returns 0 on eof, 1 on good read */
  1081. FILE    *buf;
  1082.     {
  1083.     int code;
  1084.  
  1085.     code = fscanf(buf,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~\n",
  1086.             u_fname,
  1087.             u_lname,
  1088.             u_password,
  1089.             u_time1,
  1090.             u_date1,
  1091.             u_time2,
  1092.             u_date2,
  1093.             u_city);
  1094.  
  1095.     if (code < 8)
  1096.         {
  1097.         return(0);  /* all done, hit eof */
  1098.         }
  1099.     else
  1100.         {
  1101.         return(1);  /* good read */
  1102.         }
  1103.     }
  1104. /*  end of function     */
  1105.  
  1106. wrtuser(buf)
  1107. FILE    *buf;
  1108.     {
  1109.     int code;
  1110.     code = fprintf(buf,"%s~%s~%s~%s~%s~%s~%s~%s~",
  1111.             u_fname,
  1112.             u_lname,
  1113.             u_password,
  1114.             u_time1,
  1115.             u_date1,
  1116.             u_time2,
  1117.             u_date2,
  1118.             u_city);
  1119.     if (code == -1)
  1120.         {
  1121.         portsout("User file has problem writing\r\n");
  1122.         }
  1123.     else
  1124.         {
  1125.         fputs("\n",buf);    /* put lf on end of each record */
  1126.         }
  1127.     }
  1128. /*  end of function     */
  1129.  
  1130. /*  end of program      */
  1131.  
  1132.